home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / myPlatform ƒ / sHMovPlatform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  1.9 KB  |  87 lines  |  [TEXT/KAHL]

  1. /* */
  2.  
  3. /* */
  4.  
  5. #include"SAT.h"
  6. #include "myPlatform.h"
  7.  
  8. extern FacePtr    platFace; /* Global from sMovPlatform.c */
  9.  
  10. void InitHMovPlatform()
  11. {
  12. }
  13.  
  14. pascal void SetupHMovPlatform(SpritePtr me)
  15. {
  16.     Rect            r;
  17.     PolyHandle    pol;
  18.     
  19.     me->speed.h = -1 + Rand(2) * 2;
  20.     /*me->kind = -2; */
  21.     me->face = platFace; 
  22.     SetRect(&(me->hotrect), 0, 3, 60, 20);
  23. }
  24.  
  25. pascal void HandleHMovPlatform(SpritePtr me)
  26. {
  27.     me->position.h = me->position.h + me->speed.h;
  28.     if(me->position.h < 40)
  29.         me->speed.h = 1;
  30.     if(me->position.h > (offSizeH - 100))
  31.         me->speed.h = -1;
  32.  
  33.     if(me->speed.h == 0){
  34.         if(me->position.h > offSizeH/2)
  35.             me->speed.h = -1;
  36.         else
  37.             me->speed.h = 1;
  38.     }
  39.     me->layer = -me->position.v;
  40. }
  41.  
  42. pascal void HitHMovPlatform(SpritePtr me, SpritePtr him)
  43. {
  44.     int     mini, i, min;
  45.     int    diff[5];
  46.     
  47.     if(him->task != HandlePlatform) {
  48.         diff[1] = -me->hotrect2.top + (him->hotrect2.bottom);            /* TtoB */
  49.         diff[2] = -him->hotrect2.top + (me->hotrect2.bottom);            /* BtoT */
  50.         diff[3] = -me->hotrect2.left + (him->hotrect2.right);            /* LtoR */
  51.         diff[4] = -him->hotrect2.left + (me->hotrect2.right);            /* RtoL */
  52.         mini = 0;
  53.         min = 10000;
  54.         for(i = 1; i <= 4; i++)
  55.             if(min > diff[i]){
  56.                     min = diff[i];
  57.                     mini = i;
  58.             }
  59.         switch(mini){
  60.             case 1: 
  61.                     him->position.v = him->position.v - diff[1] + 1;
  62.                     him->position.h = him->position.h + me->speed.h; 
  63.                     him->kind = 10; 
  64.                     if(him->speed.v > 0)
  65.                         him->speed.v = 0;
  66.                     break;
  67.             case 2: 
  68.                     him->position.v = him->position.v + diff[2] + 1;
  69.                     if(him->speed.v < 0)
  70.                         him->speed.v = -him->speed.v;
  71.                     break;
  72.             case 3: 
  73.                     him->position.h = him->position.h - diff[3] - 1;
  74.                     him->kind = 10;
  75.                     if(him->speed.h > 0)
  76.                         him->speed.h = -him->speed.h;
  77.                     break;
  78.             case 4: 
  79.                     him->position.h = him->position.h + diff[4] + 1;
  80.                     him->kind = 10; 
  81.                     if(him->speed.h < 0)
  82.                         him->speed.h = -him->speed.h;
  83.                     break;
  84.         } /* switch */
  85.     } /* if */
  86. }
  87.